/*
 * Copyright 2009 Eat Local Food, LLC
 * Copyright (c) 2007 osCommerce (this file was written after
 * code review of osCommerce).
 *
 * This file is part of gwtCommerce.
 *
 * gwtCommerce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * gwtCommerce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gwtCommerce.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.elf.gwt.common.client.model;

import java.util.Date;

import com.google.gwt.json.client.JSONObject;

public class AbbreviatedProductModel extends AbstractModel
{	
	protected int id;
	protected int categoryId;
	protected String name; 
	protected String image;
	protected String[] imageSize = null;
	protected Date dateAvailable;
	
	public AbbreviatedProductModel()
	{
		update();
	}

	public AbbreviatedProductModel(JSONObject jsonObject)
	{
		update();

		id = convertToInteger(jsonObject, "id");
		categoryId = convertToInteger(jsonObject, "categories_id");
		name = convertToString(jsonObject, "name");
		image = convertToString(jsonObject, "image");
		double imageWidth = convertToDouble(jsonObject, "image_width");
		double imageHeight = convertToDouble(jsonObject, "image_height");
		imageSize = adjustedImageSize(imageWidth, imageHeight, 50, 50);
		dateAvailable = convertToDate(jsonObject, "date_available");
	}

	public void update()
	{
		id = -1;
		categoryId = -1;
		name = ""; 
		image = "";
		imageSize = new String[2];
		imageSize[0] = "1";
		imageSize[1] = "1";
		dateAvailable = null;
	}

	public void update(AbbreviatedProductModel model)
	{
		id = model.getId();
		categoryId = model.getCategoryId();
		name = model.getName(); 
		image = model.getImage();
		imageSize = model.getImageSize();
		dateAvailable = model.getDateAvailable();
	}

	public int getId() {
		return id;
	}

	public int getCategoryId() {
		return categoryId;
	}

	public String getName() {
		return name;
	}
	
	public String getImage() {
		return image;
	}

	public String[] getImageSize() {
		return imageSize;
	}
	
	public Date getDateAvailable() {
		return dateAvailable;
	}
}
